The test that we choose to analyze the NYC subway data is a Mann-Whitney U-test for a two tailed test. We analyze two conditions.The ridership during rainy days and the ridership during non-rainy days. The null hypothesis would be that a randomly selected value from the population with the larger mean rank which is the ridership in rainy days(see 1.3 answer below) is equal to a randomly selected value from the other population with the lower mean which is the ridership in non rainy days. And the alternative hypothesis would be that a randomly selected value from the population with the larger mean rank which is the ridership in rainy days is greater than a randomly selected value from the other population with the lower mean which is the ridership in non rainy days. The p-value for a two tailed t-test is twice the p-value output from the Mann-Whitney U Test. In our case, the p-value output is 0.024999912793489721 and the double is close to 0.05.
Our samples are not normally distributed. Thus, we cannot use the welch's t-test for normally distributed independent samples.
do_rain_mean, no_rain_mean, U, p = (1105.4463767458733, 1090.278780151855, 1924409167.0, 0.024999912793489721)
Our p-critical value is a bit lower than 0.05. Thus we assume that our test is statistically significant. The mean for rainy days is larger than the mean for non rainy days. So we reject the null hypothesis, meaning that a randomly selected value from the population with the larger mean rank which is the ridership in rainy days is greater than a randomly selected value from the other population with the lower mean which is the ridership in non rainy days.
OLS using Statsmodels
I used 'rain', 'precipi', 'Hour', 'meantempi'and 'fog' as input variables, 'UNIT' as dummy variable and 'ENTRIESn_hourly' as an output(values).
I supposed that these features would have a higher theta level. This could be tested with gradient descent.
The coefficients were the following 'rain' = -4.7007 'precipi' = -30.5838 'Hour' = 57.9852 'meantempi' = -12.3691 'fog' = 225.8609 constant = 1222.5636
R^2 = 0.47924770782
In order to be more accurate and evaluate the effectiveness of our model, we should calculate the coefficient of determination R^2. The closer this value is to 1, the better our model. In our case the R^2 is high enough to assume that we have a valuable model. Later, by calculating the residual frequency plot: {(turnstile_weather['ENTRIESn_hourly'] - predictions).plot(kind = 'hist', bins = 70) plt.axis([-12000, 12000, 0, 5000])} one can observe that the overall pattern of the residuals is similar to the bell-shaped pattern observed when plotting a histogram of normally distributed data. This gives us with proof that our assumptions are reasonable and our choice of model is appropriate. Nevertheless, the histogram of the residuals has long tails, which suggests that there are some very large residuals a reason to question our linear regression model.
%matplotlib inline
import numpy as np
import pandas
import matplotlib.pyplot as plt
import csv
turnstile_weather = pandas.read_csv('C:/Users/oikonomakisa/Desktop/turnstile_data_master_with_weather.csv')
#def entries_histogram(turnstile_weather):
plt.figure()
no_rain = turnstile_weather['ENTRIESn_hourly'][turnstile_weather['rain'] == 0]
do_rain = turnstile_weather['ENTRIESn_hourly'][turnstile_weather['rain'] == 1]
no_rain.hist(bins = 150, stacked=True, label = 'No Rain')
do_rain.hist(bins = 150, stacked=True, label = 'Rain')
plt.xlabel('ENTRIESn_hourly')
plt.ylabel('Frequency')
plt.title('Histogram of ENTRIESn_hourly')
plt.legend(loc='upper right')
plt.axis([0, 6000, 0, 45000])
# return plt
From the above output, one can observe that the frequency of ridership at non rainy day is higher in low entries hourly. Which means that the train stations are emptier when in sunny days compared to rainy days.
%matplotlib inline
from pandas import *
from ggplot import *
turnstile_weather = pandas.read_csv('C:/Users/oikonomakisa/Desktop/turnstile_data_master_with_weather.csv')
pandas.options.mode.chained_assignment = None
turnstile_weather['weekday'] = pandas.to_datetime(turnstile_weather['DATEn']).apply(lambda x: x.strftime('%w'))
total = turnstile_weather.groupby(['weekday'], as_index=False)['ENTRIESn_hourly'].sum()
label_list = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
plot = ggplot(total, aes('weekday', 'ENTRIESn_hourly')) + geom_bar(stat = 'identity', color = 'blue') + ggtitle('Total Entries per Day') + scale_x_discrete(labels = label_list) + xlab('Day') + ylab('Rides')
plot
One can observe that the ridership in weekends is lower than in weekdays.
From the anlysis and interpretation of the data, one can observe that the ridership in rainy days is a bit greater than the ridership in non rainy days.
We rejected the null hypothesis, using the Mann-Whitney U test, by observing the means and the p-value for a two-tailed test. Since the p-value is lower than the alpha level of 0.05, we ended up to say that we have a statistically significant conclusion.
The residual normality testing in question 2.6 above, examined the fact that the histogram of the residuals has long tails, which suggests that there are some very large residuals a reason to question our linear regression model. Moreover, because there are many variables included in the dataset that might be very closely related, such as minimum, mean and maximum temperature, it may be difficult to disentangle the effects of such similar features and we may run the risk of problems with collinearity, which can cause some linear regression algorithms to give incorrect results. Lastly, I don't think that the model covers a long enough time span in order to make a more reliable prediction.